

data$forcing = as.integer(as.Date("1990-11-04"))- as.integer(as.Date(data$dob))
data$Cutoff08 = ifelse(data$forcing >= 0, 1, 0)





################# DV: Vote 2016 ########################

ivmod1_white_male = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_male_white", 
                                               downstream_voted = "vote.gen2016_male_white", downstream_lag = "lag2016_male_white", bandwidth = 365, state.abbrev=NULL)

ivmod1_black_male = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_male_black", 
                             downstream_voted = "vote.gen2016_male_black", downstream_lag = "lag2016_male_black", bandwidth = 365, state.abbrev=NULL)

ivmod1_hispanic_male = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_male_hispanic", 
                                            downstream_voted = "vote.gen2016_male_hispanic", downstream_lag = "lag2016_male_hispanic", bandwidth = 365, state.abbrev=NULL)


ivmod1_white_female = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_female_white", 
                                                 downstream_voted = "vote.gen2016_female_white", downstream_lag = "lag2016_female_white", bandwidth = 365, state.abbrev=NULL)

ivmod1_black_female = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_female_black", 
                                                 downstream_voted = "vote.gen2016_female_black", downstream_lag = "lag2016_female_black", bandwidth = 365, state.abbrev=NULL)

ivmod1_hispanic_female = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_female_hispanic", 
                                                    downstream_voted = "vote.gen2016_female_hispanic", downstream_lag = "lag2016_female_hispanic", bandwidth = 365, state.abbrev=NULL)


##################### DV: Vote 2014 ##########################

ivmod2_white_male = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_male_white", 
                                            downstream_voted = "vote.gen2014_male_white", downstream_lag = "lag2014_male_white", bandwidth = 365, state.abbrev=NULL)
ivmod2_black_male = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_male_black", 
                                            downstream_voted = "vote.gen2014_male_black", downstream_lag = "lag2014_male_black", bandwidth = 365, state.abbrev=NULL)
ivmod2_hispanic_male = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_male_hispanic", 
                                               downstream_voted = "vote.gen2014_male_hispanic", downstream_lag = "lag2014_male_hispanic", bandwidth = 365, state.abbrev=NULL)

ivmod2_white_female = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_female_white", 
                                                 downstream_voted = "vote.gen2014_female_white", downstream_lag = "lag2014_female_white", bandwidth = 365, state.abbrev=NULL)
ivmod2_black_female = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_female_black", 
                                                 downstream_voted = "vote.gen2014_female_black", downstream_lag = "lag2014_female_black", bandwidth = 365, state.abbrev=NULL)
ivmod2_hispanic_female = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_female_hispanic", 
                                                    downstream_voted = "vote.gen2014_female_hispanic", downstream_lag = "lag2014_female_hispanic", bandwidth = 365, state.abbrev=NULL)


##################### DV: Vote 2012 ##########################

ivmod3_white_male = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_male_white", 
                                            downstream_voted = "vote.gen2012_male_white", downstream_lag = "lag2012_male_white", bandwidth = 365, state.abbrev=NULL)
ivmod3_black_male = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_male_black", 
                                            downstream_voted = "vote.gen2012_male_black", downstream_lag = "lag2012_male_black", bandwidth = 365, state.abbrev=NULL)
ivmod3_hispanic_male = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_male_hispanic", 
                                               downstream_voted = "vote.gen2012_male_hispanic", downstream_lag = "lag2012_male_hispanic", bandwidth = 365, state.abbrev=NULL)


ivmod3_white_female = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_female_white", 
                                                 downstream_voted = "vote.gen2012_female_white", downstream_lag = "lag2012_female_white", bandwidth = 365, state.abbrev=NULL)
ivmod3_black_female = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_female_black", 
                                                 downstream_voted = "vote.gen2012_female_black", downstream_lag = "lag2012_female_black", bandwidth = 365, state.abbrev=NULL)
ivmod3_hispanic_female = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_female_hispanic", 
                                                    downstream_voted = "vote.gen2012_female_hispanic", downstream_lag = "lag2012_female_hispanic", bandwidth = 365, state.abbrev=NULL)



##################### DV: Vote 2010 ##########################


ivmod4_white_male = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_male_white", 
                                            downstream_voted = "vote.gen2010_male_white", downstream_lag = "lag2010_male_white", bandwidth = 365, state.abbrev=NULL)
ivmod4_black_male = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_male_black", 
                                            downstream_voted = "vote.gen2010_male_black", downstream_lag = "lag2010_male_black", bandwidth = 365, state.abbrev=NULL)
ivmod4_hispanic_male = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_male_hispanic", 
                                               downstream_voted = "vote.gen2010_male_hispanic", downstream_lag = "lag2010_male_hispanic", bandwidth = 365, state.abbrev=NULL)

ivmod4_white_female = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_female_white", 
                                                 downstream_voted = "vote.gen2010_female_white", downstream_lag = "lag2010_female_white", bandwidth = 365, state.abbrev=NULL)
ivmod4_black_female = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_female_black", 
                                                 downstream_voted = "vote.gen2010_female_black", downstream_lag = "lag2010_female_black", bandwidth = 365, state.abbrev=NULL)
ivmod4_hispanic_female = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_female_hispanic", 
                                                    downstream_voted = "vote.gen2010_female_hispanic", downstream_lag = "lag2010_female_hispanic", bandwidth = 365, state.abbrev=NULL)


##################### DV: Democrat ##########################


ivmod5_white_male = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_male_white", 
                                            downstream_voted = "democrat_male_white", downstream_lag = "lagdem_male_white", bandwidth = 365, state.abbrev=NULL)
ivmod5_black_male = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_male_black", 
                                            downstream_voted = "democrat_male_black", downstream_lag = "lagdem_male_black", bandwidth = 365, state.abbrev=NULL)
ivmod5_hispanic_male = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_male_hispanic", 
                                               downstream_voted = "democrat_male_hispanic", downstream_lag = "lagdem_male_hispanic", bandwidth = 365, state.abbrev=NULL)


ivmod5_white_female = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_female_white", 
                                                 downstream_voted = "democrat_female_white", downstream_lag = "lagdem_female_white", bandwidth = 365, state.abbrev=NULL)
ivmod5_black_female = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_female_black", 
                                                 downstream_voted = "democrat_female_black", downstream_lag = "lagdem_female_black", bandwidth = 365, state.abbrev=NULL)
ivmod5_hispanic_female = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_female_hispanic", 
                                                    downstream_voted = "democrat_female_hispanic", downstream_lag = "lagdem_female_hispanic", bandwidth = 365, state.abbrev=NULL)


##################### DV: Republican ##########################


ivmod_rep_white_male = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_male_white", 
                                            downstream_voted = "republican_male_white", downstream_lag = "lagrep_male_white", bandwidth = 365, state.abbrev=NULL)
ivmod_rep_black_male = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_male_black", 
                                            downstream_voted = "republican_male_black", downstream_lag = "lagrep_male_black", bandwidth = 365, state.abbrev=NULL)
ivmod_rep_hispanic_male = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_male_hispanic", 
                                               downstream_voted = "republican_male_hispanic", downstream_lag = "lagrep_male_hispanic", bandwidth = 365, state.abbrev=NULL)

ivmod_rep_white_female = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_female_white", 
                                                    downstream_voted = "republican_female_white", downstream_lag = "lagrep_female_white", bandwidth = 365, state.abbrev=NULL)
ivmod_rep_black_female = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_female_black", 
                                                    downstream_voted = "republican_female_black", downstream_lag = "lagrep_female_black", bandwidth = 365, state.abbrev=NULL)
ivmod_rep_hispanic_female = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_female_hispanic", 
                                                       downstream_voted = "republican_female_hispanic", downstream_lag = "lagrep_female_hispanic", bandwidth = 365, state.abbrev=NULL)




##################### Registered ##########################


ivmod6_white_male = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_male_white", 
                                            downstream_voted = "registered_male_white", downstream_lag = "lagregistered_male_white", bandwidth = 365, state.abbrev=NULL)
ivmod6_black_male = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_male_black", 
                                            downstream_voted = "registered_male_black", downstream_lag = "lagregistered_male_black", bandwidth = 365, state.abbrev=NULL)
ivmod6_hispanic_male = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_male_hispanic", 
                                               downstream_voted = "registered_male_hispanic", downstream_lag = "lagregistered_male_hispanic", bandwidth = 365, state.abbrev=NULL)


ivmod6_white_female = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_female_white", 
                                                 downstream_voted = "registered_female_white", downstream_lag = "lagregistered_female_white", bandwidth = 365, state.abbrev=NULL)
ivmod6_black_female = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_female_black", 
                                                 downstream_voted = "registered_female_black", downstream_lag = "lagregistered_female_black", bandwidth = 365, state.abbrev=NULL)
ivmod6_hispanic_female = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_female_hispanic", 
                                                    downstream_voted = "registered_female_hispanic", downstream_lag = "lagregistered_female_hispanic", bandwidth = 365, state.abbrev=NULL)







rm(data)
filename = paste0("results_", state, "_gender.Rdata")
save.image(paste0("results/", filename))
rm(list=ls(pattern = "mod"))
